package cn.tedu.blackhorse.controller;

import cn.tedu.blackhorse.pojo.dto.SalaryAddNewDTO;
import cn.tedu.blackhorse.pojo.vo.SalaryListItemVO;
import cn.tedu.blackhorse.pojo.vo.SalaryStandardVO;
import cn.tedu.blackhorse.service.ISalaryService;
import cn.tedu.blackhorse.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/salary")
@Api(tags = "管理工资模块")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @PostMapping("/addNew")
    @ApiOperation("新增工资")
    public JsonResult<Void> addNew(SalaryAddNewDTO salaryAddNewDTO){
        salaryService.insertSalary(salaryAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除工资表")
    public JsonResult<Void> deleteSalary(@PathVariable Long teacherId){
        salaryService.deleteSalary(teacherId);
        return JsonResult.ok();
    }

    @GetMapping("/")
    @ApiOperation("获取全部工资列表")
    public JsonResult<List<SalaryListItemVO>> list(){
        List<SalaryListItemVO> list = salaryService.list();
        return JsonResult.ok(list);
    }

    @GetMapping("/{teacherId:[0-9]+}")
    @ApiOperation("根据老师id查询相关工资详情")
    public JsonResult<SalaryStandardVO> getById(@PathVariable Long teacherId){
        SalaryStandardVO standardVO = salaryService.getByTeacherId(teacherId);
        return JsonResult.ok(standardVO);
    }


}
